package com.netitv.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.netitv.dao.analysisDao;
import com.netitv.domain.Channel;
import com.netitv.domain.channel_orderDetail;

public class analysisDaoImpl extends JdbcDaoSupport implements analysisDao{

	@Override
	public List<channel_orderDetail> ChannelAnalysis(String time) {
		// TODO Auto-generated method stub
		time+="%";
		String sql="select channel.id,channel.name,count(channel.name) from channel,orderdetail where channel.id=orderdetail.channelid and orderdetail.serstarttime like ? group by channel.id";

		return (List<channel_orderDetail>)this.getJdbcTemplate().query(sql,new Object[]{time},new ChannelMapper());
	}
	protected class ChannelMapper implements RowMapper {
		public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
			
			channel_orderDetail channel = new channel_orderDetail();
			channel.setChannelid(rs.getInt(1));
			channel.setChannelname(rs.getString(2));
			channel.setOrderDetailCount(rs.getInt(3));
			return channel;
		}
	}

}
